package com.wqh;

import com.wqh.data.collection.dao.WeatherCollectionDao;
import com.wqh.sevice.pojo.WeatherResponse;
import com.wqh.sevice.weather.WeatherDataService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author wanqh
 * @date 2018/02/10 15:14
 * @description:
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/spring-context.xml"})
@Slf4j
public class testRedis {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private WeatherCollectionDao weatherCollectionDao;
    @Test
    public void redisTest(){
        String body = "测试测试测试";
        String key = "测试";
        ValueOperations<String, String> ops = redisTemplate.opsForValue();
//        ResponseEntity<String> responseEntity = restTemplate.getForEntity(uri, String.class);
//        if(200 == responseEntity.getStatusCodeValue()){
//            body = responseEntity.getBody();
//        }
        //将数据保存到缓存。一个参数是key ，第二个是保存的value，第三个是有效期，第四个是有效期的单位
        weatherCollectionDao.dataCollection("101280204");
//        ops.set(key,body);
    }

    @Autowired
    private WeatherDataService weatherDataService;

    @Test
    public void testWeathe(){
        WeatherResponse dataByCityId = weatherDataService.getDataByCityId("101280101");
        log.info("测试===========>>>>>> {}",dataByCityId);
    }
}
